package com.xiaohong.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.goods.dao.CategoryMapper;
import com.xiaohong.goods.pojo.Category;
import com.xiaohong.goods.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;


    /**
     * 条件+分页查询Category
     * @param category 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Category> findPage(Category category, int page, int size){
        // 构建查询条件
        QueryWrapper<Category> queryWrapper = new QueryWrapper<Category>(category);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return categoryMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Category
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Category> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return categoryMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Category
     * @param category
     * @return
     */
    @Override
    public List<Category> findList(Category category){
        // 构建查询条件
        QueryWrapper<Category> queryWrapper = new QueryWrapper<Category>(category);
        // 查询数据
        return categoryMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Category
     * @param id
     */
    @Override
    public void delete(Integer id){
        categoryMapper.deleteById(id);
    }

    /**
     * 根据ID修改Category
     * @param category
     */
    @Override
    public void update(Category category){
        categoryMapper.updateById(category);
    }

    /**
     * 增加Category
     * @param category
     */
    @Override
    public void add(Category category){
        categoryMapper.insert(category);
    }

    /**
     * 根据ID查询Category
     * @param id
     * @return
     */
    @Override
    public Category findById(Integer id){
        return  categoryMapper.selectById(id);
    }

    /**
     * 查询全部Category数据
     * @return
     */
    @Override
    public List<Category> findAll() {
        return categoryMapper.selectList(null);
    }
}
